//方向，类型，难度 等定义
const diffMixin = {
    data() {
        return {
            diffArr: [
                {
                    key: 'Simple',
                    value: '简单',
                    color: '#00b343'
                },
                {
                    key: 'Medium',
                    value: '中等',
                    color: '#fa7300'
                },
                {
                    key: 'Hard',
                    value: '较难',
                    color: '#ed4014'
                }
            ]
        };
    },
    methods: {
        // 困难程度
        handleDiff(val) {
            let diffMap = new Map(this.diffArr.map((diff) => [diff.key, diff.value]));
            if (val === 'Commonly' || val === 'Medium' || val === 'commonly' || val === 'medium') {
                return diffMap.get('Medium');
            } else if (val === 'Hard' || val === 'hard') {
                return diffMap.get('Hard');
            } else if (val === 'simple' || val === 'Simple') {
                return diffMap.get('Simple');
            } else {
                return '';
            }
        },
        handleDiffColor(val) {
            let diffMap = new Map(this.diffArr.map((diff) => [diff.key, diff.color]));
            if (val === 'Commonly' || val === 'Medium' || val === 'commonly' || val === 'medium') {
                return diffMap.get('Medium');
            } else if (val === 'Hard' || val === 'hard') {
                return diffMap.get('Hard');
            } else if (val === 'simple' || val === 'Simple') {
                return diffMap.get('Simple');
            } else {
                return '';
            }
        }
    }
};
import { mapState, mapGetters, mapActions } from 'vuex';
const typeAndDirectionMixin = {
    data() {
        return {
            // 课件类型
            // directionData: [], //所有
            // typeArr: [], //二级
            // directionArr: [], //一级
            // treeDirectionData: []
            showTypeArr: []
        };
    },
    computed: {
        ...mapState('common', ['directionData']),
        ...mapGetters('common', ['treeDirectionData', 'directionArr', 'typeArr'])
    },
    watch: {
        typeArr(val) {
            this.showTypeArr = val;
        }
    },
    mounted() {
        if (this.directionData.length === 0) {
            this.getAllDirection();
        } else {
            this.showTypeArr = this.typeArr;
        }
    },
    methods: {
        ...mapActions('common', ['getAllDirection']),
        // 课程方向
        // getAllDirection() {
        //     this.setAllPoint(directionData);
        //     allDirection({ dictTypeID: 'newDirectionType' })
        //         .then((data) => {
        //             if (data.code == 1) {
        //                 let attribute = data.attribute.attribute[0];
        //                 let directionData = attribute.dictEntryList;
        //                 directionData.forEach((dict) => {
        //                     dict.key = dict.dictid;
        //                     dict.value = dict.dictname;
        //                 });
        //                 this.setAllPoint(directionData);
        //             }
        //         })
        //         .catch((error) => {
        //             this.$Message.error('获取方向错误，请稍后再试!');
        //         });
        // },
        //类型
        handleCodeType(dictid) {
            let dictMap = {};
            this.directionData.forEach((exp) => {
                dictMap[exp.dictid] = exp.dictname;
            });
            return dictMap[dictid] || '未知类型';
        },
        //方向
        handleDirection(dictid) {
            let type = this.directionData.find((dict) => dict.dictid == dictid);
            let direction = '';
            if (type) {
                direction = this.directionData.find((dict) => dict.dictid == type.parentid)
                    .dictname;
            }
            return direction || '未知类型';
        },
        //方向/类型
        handleCodeTypeAndDirection(val) {
            if (!val) {
                return '-';
            }
            //获取所有方向
            let arr = [];
            let splitVal = val.split(',');
            let typeCodeObj = this.directionData || [];
            splitVal.forEach((split) => {
                let curCode = typeCodeObj.find((code) => code.dictid === split);
                if (curCode) {
                    arr.push(curCode.dictname);
                }
            });
            if (arr.length === 0) {
                arr = ['未知类型'];
            }
            return arr.join(` / `);
        },
        //通过方向获取类型
        filterTypeWithDirection(name) {
            if (name == 'All') {
                this.showTypeArr = this.directionData.filter((dict) => dict.parentid);
            } else {
                this.showTypeArr = this.directionData.filter((dict) => dict.parentid == name);
            }
        }
    }
};
const experTypeMixin = {
    data() {
        return {
            experTypeArr: [
                {
                    key: 0,
                    value: '实操课件'
                },
                {
                    key: 1,
                    value: '理论课件'
                },
                {
                    key: 2,
                    value: '文本课件'
                }
            ]
        };
    },
    methods: {
        handleExperType(val) {
            let typeInfo = this.experTypeArr.find((type) => type.key === val);
            return typeInfo ? typeInfo.value : '未定义类型';
        }
    }
};
const visibleMixin = {
    data() {
        return {
            visibleArr: [
                {
                    key: '0',
                    value: '个人',
                    color: 'rgb(255, 165, 0)'
                },
                {
                    key: '1',
                    value: '单位',
                    color: 'rgb(50, 205, 50)'
                },
                {
                    key: '2',
                    value: '系统',
                    color: 'rgb(65, 105, 225)'
                }
            ],
            visibleArrString: [
                {
                    key: 'private',
                    value: '个人',
                    color: 'rgb(255, 165, 0)'
                },
                {
                    key: 'share',
                    value: '单位',
                    color: 'rgb(50, 205, 50)'
                },
                {
                    key: 'public',
                    value: '系统',
                    color: 'rgb(65, 105, 225)'
                }
            ]
        };
    },
    computed: {
        allVisibleList() {
            return [{ key: 'all', value: '全部' }, ...this.visibleArr];
        },
        allVisibleListString() {
            return [{ key: 'all', value: '全部' }, ...this.visibleArrString];
        }
    },
    methods: {
        filterVisible(val, type) {
            let typeInfo =
                this.visibleArr.find((type) => type.key === val) ||
                this.visibleArrString.find((type) => type.key === val);
            if (type === 'color') {
                return typeInfo ? typeInfo.color : '';
            } else {
                return typeInfo ? typeInfo.value : '未定义';
            }
        }
    }
};
const imagePathDealMixin = {
    data() {
        return {
            defImg: require('../assets/scene/default.png')
        };
    },
    methods: {
        // 图片路径
        handleImage(logo, defImg) {
            let src = '';
            if (logo) {
                if (logo.indexOf('Learn') > -1) {
                    src = logo;
                } else {
                    src = `/Learn/${logo}`;
                }
            } else {
                src = defImg || this.defImg;
            }
            return src;
        },
        setDefImg(event, defImg) {
            let img = event.srcElement;
            img.src = defImg || this.defImg;
            img.onerror = null;
        }
    }
};
const deployStatusMixin = {
    data() {
        return {
            deployStatusArr: [
                {
                    key: '0',
                    value: '未部署',
                    color: 'var(--status-pre)'//'#888'
                    //   icon: require('../assets/class/icon_wbs.png')
                },
                {
                    key: '1',
                    value: '部署中',
                    color: 'var(--status-ing)'//'#06b649'
                    //   icon: require('../assets/class/icon_bscg.png')
                },
                {
                    key: '2',
                    value: '待部署',
                    color: 'var(--status-pre)' //'#888'
                    //   icon: require('../assets/class/icon_bscg.png')
                },
                {
                    key: '3',
                    value: '部署成功',
                    color: 'var(--status-yes)' //'#06b649'
                    //   icon: require('../assets/class/icon_bscg.png')
                },
                {
                    key: '4',
                    value: '导入失败',
                    color: 'var(--status-deling)' //'#ff4242'
                    //   icon: require('../assets/class/icon_bssb.png')
                },
                {
                    key: '5',
                    value: '已编辑',
                    color: 'var(--status-pre)' //'#888'
                    //   icon: require('../assets/class/icon_bssb.png')
                },
                {
                    key: '6',
                    value: '部署失败',
                    color: 'var(--status-no)' //'#ff4242'
                    //   icon: require('../assets/class/icon_bssb.png')
                },
                {
                    key: '7',
                    value: '编辑错误',
                    color: 'var(--status-no)' //'#fa9901'
                    //   icon: require('../assets/class/icon_bssb.png')
                },
                {
                    key: '8',
                    value: '删除失败',
                    color: 'var(--status-no)'//'#fa9901'
                    //   icon: require('../assets/class/icon_bssb.png')
                },
                {
                    key: '9',
                    value: '部署中',
                    color: 'var(--status-ing)'//'#06b649'
                    //   icon: require('../assets/class/icon_bscg.png')
                },
                {
                    key: '10',
                    value: '未部署',
                    color: 'var(--status-pre)'//'#888'
                    //   icon: require('../assets/class/icon_wbs.png')
                },
                {
                    key: '11',
                    value: '编辑失败',
                    color: 'var(--status-no)'//'#fa9901'
                },
                {
                    key: '12',
                    value: '待删除',
                    color: 'var(--status-deling)' //'#ff8244'
                },
                {
                    key: '13',
                    value: '清空部署中',
                    color: 'var(--status-deling)'//'#ff8244'
                },
                {
                    key: '14',
                    value: '清空部署失败',
                    color: 'var(--status-no)'//'#ff8244'
                },
                {
                    key: '15',
                    value: '部署校验中',
                    color: 'var(--status-ing)'//'#088cf0'
                },
                {
                    key: '16',
                    value: '工程导入中',
                    color: 'var(--status-ing)'//'#088cf0'
                },
                {
                    key: '17',
                    value: '工程导入失败',
                    color: 'var(--status-no)'//'#ff8244'
                }
            ]
        };
    },
    methods: {
        // 状态
        filterDeployStatus(val, type) {
            let { value = '', color = '', icon = '' } =
                this.deployStatusArr.find((status) => status.key == val) || {};
            let obj = {
                color,
                text: value,
                icon
            };
            return obj[type] || 'value';
        }
    }
};
export {
    diffMixin,
    typeAndDirectionMixin,
    imagePathDealMixin,
    deployStatusMixin,
    experTypeMixin,
    visibleMixin
};
